package com.sky.controller.user;

import com.sky.dataTransmit.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {

    @Autowired
    private ShoppingCartService shoppingCartService;

    @PostMapping("/add")
    public Result add(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("添加购物车 {}",shoppingCartDTO);
        shoppingCartService.add(shoppingCartDTO);
        return Result.success("添加购物车",null);
    }

    @PostMapping("/sub")
    public Result sub(@RequestBody ShoppingCartDTO shoppingCartDTO){
        log.info("删除购物车 {}",shoppingCartDTO);
        shoppingCartService.sub(shoppingCartDTO);
        return Result.success("删除购物车",null);
    }

    @GetMapping("/list")
    public Result<List<ShoppingCart>> list(){
        log.info("查询购物车");
        List<ShoppingCart> list = shoppingCartService.getList();
        return Result.success("查询购物车",list);
    }

    @DeleteMapping("/clean")
    public Result clear(){
        log.info("清空购物车");
        shoppingCartService.clear();
        return Result.success("清空购物车",null);
    }

}
